<%--
  Created by IntelliJ IDEA.
  User: WYX
  Date: 2024/4/7
  Time: 8:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.math.BigDecimal" %>
<html>
<head>
    <title>day02</title>
</head>
<body style="text-align: center">
<jsp:useBean id="compute" class="wyx240407.Day02"/>
<%!
    String str;
%>
<form action="" method="post">
    <h3>计算器</h3>
    <label>
        <input type="text" name="a" value="0">
    </label>
    <label>
                <input type="radio" name="c" value="+" checked="checked">加
                <input type="radio" name="c" value="-">减
                <input type="radio" name="c" value="*">乘
                <input type="radio" name="c" value="/">除
                <input type="radio" name="c" value="%">取模
                <input type="radio" name="c" value="^">幂
    </label>
    <label>
        <input type="text" name="b" value="0">
    </label><br>
    <input type="submit" value="提交"><br>
    <%
        try{
            if(request.getParameter("a")!=null&&request.getParameter("b")!=null){
                BigDecimal a=new BigDecimal(request.getParameter("a"));
                BigDecimal b=new BigDecimal(request.getParameter("b"));
                compute.setA(a);
                compute.setB(b);
                compute.setC(request.getParameter("c").charAt(0));
                str= String.valueOf(compute.compute());
            }else str="输入为空！";
        }catch (Exception e){
            str="输入有误！";
            out.print(e+"<br>");
        }
    %>
    <label>
    结果<input type="text" name="result" value="<%=str%>" size="90%"><br>
        <input type="button" value="清空" onclick="window.location.href='day02.jsp'">
        <input type="button" value="返回" onclick="window.location.href='menu.jsp'">
    </label>
</form>
</body>
</html>
